import redis

from framework.utilities import to_string
from setting import REDIS_HOST, REDIS_PORT, REDIS_PWD


class BlockRedisListHelper():
    __log_pool__ = redis.ConnectionPool(host=REDIS_HOST, port=REDIS_PORT, password=REDIS_PWD)

    @classmethod
    def client(cls):
        return redis.Redis(connection_pool=cls.__log_pool__)

    @classmethod
    def append(cls, list_name, values):
        if not values: return
        try:
            return BlockRedisListHelper.client().rpush(list_name, to_string(values))
        except:
            pass

    @classmethod
    def pop_from_head(cls, list_name):
        try:
            return BlockRedisListHelper.client().lpop(list_name)
        except:
            pass


if __name__ == '__main__':
    pass
